<div class="bjui-pageContent">
    <form action="${wwwroot}/admin/dbserver/save" id="editForm" data-toggle="validate" data-alertmsg="false" reloadNavtab="true">
        <input type="hidden" name="id" value="${(dbServer.id)!}" />
        <div class="pageFormContent" data-layout-h="0">
            <table class="table table-condensed table-hover" width="100%">
                <tbody>
                    <tr>
                        <td>
                            <label for="dbType" class="control-label x85">类型：</label>
                            <#--<input type="text" name="dbType" id="dbType" value="${(dbServer.dbType)!}" data-rule="required" >-->
                            <@p.selector dbTypes 'typeName' 'note' dbServer 'dbType' 'dbTypeName'/>
                        </td>
                        <#--<td>-->
                            <#--<label for="otherParam" class="control-label x85">其他参数：</label>-->
                            <#--<input type="text" name="otherParam" id="otherParam" value="${(dbServer.otherParam)!}"  >-->
                        <#--</td>-->
                        <td>
                            <label for="alias" class="control-label x85">别名：</label>
                            <input type="text" name="alias" id="alias" value="${(dbServer.alias)!}" data-rule="required" >
                        </td>
                        <td>
                            <label for="sysRank" class="control-label x85">系统级别：</label>
                        <@p.selector systemRanks 'name' 'name' dbServer 'sysRank' 'sysRankName'/>
                        <#--<input type="text" name="sysRank" id="sysRank" value="${(agentNode.sysRank)!}"  >-->
                        </td>

                        <#--<td>-->
                            <#--<label for="groupId" class="control-label x85">分组：</label>-->
                            <#--<select name="groupId" id="groupId" data-toggle="selectpicker">-->
                                <#--<option value="">请选择</option>-->
                            <#--<#list groupTypes as groupType>-->
                                <#--<option value="${(groupType.id)!}" <#if groupType??&&groupType.id??&&dbServer.groupId??&&groupType.id==dbServer.groupId>selected</#if>>${(groupType.note)!}</option>-->
                            <#--</#list>-->
                            <#--</select>-->
                        <#--</td>-->

                    </tr>
                    <tr>

                        <td>
                            <label for="dbHost" class="control-label x85">地址：</label>
                            <input type="text" name="dbHost" id="dbHost" value="${(dbServer.dbHost)!}" data-rule="required" >
                        </td>
                        <td>
                            <label for="dbPort" class="control-label x85">端口：</label>
                            <input type="text" name="dbPort" id="dbPort" value="${(dbServer.dbPort)!}" data-rule="required" >
                        </td>
                        <td>
                            <label for="dbName" class="control-label x85">库名：</label>
                            <input type="text" name="dbName" id="dbName" value="${(dbServer.dbName)!}" data-rule="required" >
                        </td>


                    </tr>
                    <tr>

                        <td>
                            <label for="dbUser" class="control-label x85">账号：</label>
                            <input type="text" name="dbUser" id="dbUser" value="${(dbServer.dbUser)!}" data-rule="required" >
                        </td>
                        <td>
                            <label for="dbPass" class="control-label x85">密码：</label>
                            <input type="password" name="dbPass" id="dbPass" value="${(dbServer.dbPass)!}" data-rule="required" onchange="javascript:genPass()">
                        </td>
                        <td>
                            <label for="opSystem" class="control-label x85">操作系统：</label>
                        <@p.selector osTypes 'typeName' 'typeName' dbServer 'opSystem' 'opSystemName'/>
                        <#--<input type="text" name="opSystem" id="opSystem" value="${(agentNode.opSystem)!}"  >-->
                        </td>
                    </tr>
                    <tr>

                        <td>
                            <label for="bizTypeId" class="control-label x85">业务类型：</label>
                            <select name="bizTypeId" id="bizTypeId" data-toggle="selectpicker" onchange="$('#bizTypeName_').val(this.options[this.selectedIndex].text)" data-rule="required">
                                <option value="">请选择</option>
                            <#list bizTypes as type>
                                <option value="${(type.id)!}" <#if type??&&type.id??&&dbServer.bizTypeId??&&type.id==dbServer.bizTypeId>selected</#if>>${(type.typeName)!}</option>
                            </#list>
                            </select>
                            <input type="hidden" name="bizTypeName" id="bizTypeName_" value="${(dbServer.bizTypeName)!}"  >
                        </td>
                        <td>
                            <label for="agentId" class="control-label x85">代理：</label>
                            <select name="agentId" id="agentId" data-toggle="selectpicker" data-rule="required">
                                <option value="">请选择</option>
                            <#list agents as ag>
                                <option value="${(ag.id)!}" <#if ag??&&ag.id??&&dbServer.agentId??&&ag.id==dbServer.agentId>selected</#if>>${(ag.name)!}</option>
                            </#list>
                            </select>
                        </td>
                        <td>
                            <label for="note" class="control-label x85">备注：</label>
                            <input type="text" name="note" id="note" value="${(dbServer.note)!}"  >
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label for="team" class="control-label x85">组别：</label>
                            <select name="team" id="team" data-toggle="selectpicker"  data-rule="required">
                                <option value="">请选择</option>
                            <#list teams as team>
                                <option value="${(team)!}" <#if team??&&team.value??&&dbServer.team??&&team==dbServer.team>selected</#if>>${(team.label)!}</option>
                            </#list>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <a class="btn btn-success" href="javascript:testConnect();">测试连接</a>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </form>
</div>
<div class="bjui-pageFooter" >
    <ul>
        <li><button type="button" class="btn btn-close" data-icon="close">取消</button></li>
        <li><button type="submit" class="btn btn-success" data-icon="save">保存</button></li>
    </ul>
</div>
<script>
    function genPass()
    {
        var pass = $('#dbPass').val();
        $.ajax({
            url: "/admin/pass/encrypt"
            , type: "POST"
            , data: "pass="+pass
            , success: function( data, textStatus, jqXHR ){
                $('#dbPass').val(data)
            }
        });
    }
    function testConnect()
    {
        var dbHost = $('#editForm input[id=dbHost]').val();
        var dbType = $('#editForm select[id=dbType]').val();
        var dbName = $('#editForm input[id=dbName]').val();
        var dbUser = $('#editForm input[id=dbUser]').val();
        var dbPass = $('#editForm input[id=dbPass]').val();
        var dbPort = $('#editForm input[id=dbPort]').val();

        $.ajax({
            url: "/admin/dbserver/testconnect"
            , type: "POST"
            , data: "dbHost="+dbHost+"&dbType="+dbType+"&dbName="+dbName+
                "&dbUser="+dbUser+"&dbPass="+dbPass+"&dbPort="+dbPort+"&random="+new Date().getTime()
            ,timeout:5000
            , success: function( data, textStatus, jqXHR ){
                alert(data);
//                if(data=='true')
//                {
//                    alert("连接成功！");
//                }
//                else
//                {
//                    alert("连接失败，请检查参数！");
//                }
            }
        });

    }
</script>